﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.EntityClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using DocumentInterchange.Filters;
using DocumentInterchange.Models;
using WebMatrix.WebData;

namespace DocumentInterchange.Common
{
	public class ClientsAccess
	{
		private static ClientContext context = new ClientContext();

		static ClientsAccess()
		{
			var state = context.Database.Connection.State;
			Database.SetInitializer<ClientContext>(null);

			//((EntityConnection)context.Database.Connection).Open();
		}

		public static string getClientName()
		{
			if (WebSecurity.IsAuthenticated)
			{
				int id = WebSecurity.CurrentUserId;
				return context.Clients.First(x=> x.UserId == id).Name;
			}
			return "";
		}

		public static string getClientCompany()
		{
			if (WebSecurity.IsAuthenticated)
			{
				int id = context.Clients.First(y => y.UserId == WebSecurity.CurrentUserId).Company;

				return context.Companies.First(x => x.Id == id).CompanyName;
			}
			return "";
		}
	}
}